home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
mint
/
duftp
/
servers.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-17
|
8KB
|
302 lines
/*
DUFTP
*/
// Server List Handling
#include <DULIB.H>
#include <stdio.h>
#include "servers.h"
#include "duftp_n.h"
#include "globals.h"
#include "ftp.h"
server_list *servers;
server_list *selected_server;
short server_count;
char *server_name_list[MAX_SERVERS];
#define MAX_STD_LENGTH 40
// default root account on my own machine, this sets the password to popwilleat, so you have to change it to your own machine
// or even better, don't use it and make sure the bookmarks file SERVERS.INF exists
const server_list servers_default = {"Localhost (this machine) ","localhost","root","popwilleat ","/"};
void load_servers(void)
{
FILE *s;
char linebuf[200];
server_list *ns;
s=fopen("SERVERS.INF","r"); // Check for both cases of the servers.inf file
if (!s) // (request by Ben Ball)
s=fopen("servers.inf","r");
if (s)
{
servers=NULL;
server_count=0;
fgets(linebuf,199,s); // Skip title line
while(!feof(s))
{
ns=(server_list*)malloc(sizeof(server_list));
fgets(linebuf,199,s);
linebuf[strlen(linebuf)-1]='\0';
ns->name=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
sprintf(ns->name,"%s",linebuf);
fgets(linebuf,199,s);
linebuf[strlen(linebuf)-1]='\0';
ns->ip_name=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
sprintf(ns->ip_name,"%s",linebuf);
fgets(linebuf,199,s);
linebuf[strlen(linebuf)-1]='\0';
ns->login=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
sprintf(ns->login,"%s",linebuf);
fgets(linebuf,199,s);
linebuf[strlen(linebuf)-1]='\0';
ns->password=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
sprintf(ns->password,"%s",linebuf);
ns->next=servers;
fgets(linebuf,199,s);
linebuf[strlen(linebuf)-1]='\0';
ns->path=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
sprintf(ns->path,"%s",linebuf);
ns->next=servers;
servers=ns;
server_name_list[server_count]=ns->name;
server_count++;
}
fclose(s);
for(selected_server=servers; selected_server->next; selected_server=selected_server->next);
}else{
selected_server=servers=&servers_default; // Use the internal default
server_name_list[0]=servers->name;
server_count=1;
form_alert(1,"[1][ WARNING: Cann't find yours SERVERS.INF file. | Using internal default. ][ ok ]");
}
}
short save_servers(void)
{
FILE *s;
server_list *ns;
if (servers==&servers_default) return TRUE; // Don't save the internal default
chdir(initial_dir);
s=fopen("SERVERS.INF","w");
if (s)
{
fprintf(s,"DUFTP SERVERS FILE");
for(ns=servers; ns; ns=ns->next)
{
fprintf(s,"\n%s\n%s\n%s\n%s\n%s",ns->name,ns->ip_name,ns->login,ns->password,ns->path);
}
fprintf(s,"*");
fclose(s);
}else{
form_alert(1,"[3][ WARNING: Cann't open SERVERS.INF file. ][ ok ]");
}
return TRUE;
}
short add_new_server(void)
{
OBJECT *a;
server_list *ns;
short f;
ns=(server_list*)malloc(sizeof(server_list));
ns->password=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
ns->path=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
ns->name=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
ns->login=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
ns->ip_name=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
for(f=0; f<MAX_STD_LENGTH; f++)
{
ns->password[f]=' ';
ns->path[f]=' ';
ns->name[f]=' ';
ns->login[f]=' ';
ns->ip_name[f]=' ';
}
ns->password[MAX_STD_LENGTH-1]='\0';
ns->path[MAX_STD_LENGTH-1]='\0';
ns->name[MAX_STD_LENGTH-1]='\0';
ns->login[MAX_STD_LENGTH-1]='\0';
ns->ip_name[MAX_STD_LENGTH-1]='\0';
sprintf(ns->name,"NEW ");
if (ns==&servers_default)
ns->next=NULL;
else
ns->next=servers;
servers=ns;
server_name_list[server_count]=ns->name;
server_count++;
// Update the list of servers to include our new server
Change_scroll_list(Hosts, Listhosts, server_name_list, server_count);
// Make the current editable texts our new ones
set_dialog_text(Hosts, Server_name, ns->name);
set_dialog_text(Hosts, Ip_address, ns->ip_name);
set_dialog_text(Hosts, Login_name, ns->login);
set_dialog_text(Hosts, Login_password, ns->password);
set_dialog_text(Hosts, Login_path, ns->path);
rsrc_gaddr(0,Hosts,&a);
objc_draw(a,Server_name,0,scrn_x,scrn_y,scrn_w,scrn_h);
objc_draw(a,Ip_address,0,scrn_x,scrn_y,scrn_w,scrn_h);
objc_draw(a,Login_name,0,scrn_x,scrn_y,scrn_w,scrn_h);
objc_draw(a,Login_password,0,scrn_x,scrn_y,scrn_w,scrn_h);
objc_draw(a,Login_path,0,scrn_x,scrn_y,scrn_w,scrn_h);
return TRUE;
}
short add_current_server(void)
{
server_list *ns;
short mb,junk;
if (!connected) form_alert(1,"[1][ Cann't add bookmark | - not connected. ][ Cancel ]");
ns=(server_list*)malloc(sizeof(server_list));
ns->password=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
ns->name=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
ns->login=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
ns->ip_name=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
ns->path=(char*)malloc(sizeof(char)*MAX_STD_LENGTH);
sprintf(ns->name,"New Bookmark ");
sprintf(ns->login, "%s", new_server_login);
sprintf(ns->ip_name, "%s", new_server_address);
sprintf(ns->password, "%s", new_server_password);
sprintf(ns->path, "%s/", new_server_path);
ns->next=servers;
servers=ns;
server_name_list[server_count]=ns->name;
server_count++;
// Update the list of servers to include our new server
Change_scroll_list(Hosts, Listhosts, server_name_list, server_count);
// Make the current editable texts our new ones
set_dialog_text(Hosts, Server_name, ns->name);
set_dialog_text(Hosts, Ip_address, ns->ip_name);
set_dialog_text(Hosts, Login_name, ns->login);
set_dialog_text(Hosts, Login_password, ns->password);
set_dialog_text(Hosts, Login_path, ns->path);
Set_dialog_Kfocus(Hosts, Server_name);
dialog_update(Hosts);
for(mb=1; mb; graf_mkstate(&junk,&junk,&mb,&junk));
return TRUE;
}
short popup_select_server(void)
{
char **list;
short f,s,current;
server_list *l;
l=servers;
list=(char**)malloc(sizeof(char*)*(server_count+2));
for(f=server_count; f>0; f--)
{
list[f]=(char*)malloc(sizeof(char)*(strlen(l->name)+2));
sprintf(list[f],"%s",l->name);
if (selected_server==l) current=f;
l=l->next;
}
list[0]="SELECT FTP SITE";
s=form_popup(this_dialog, this_ob, server_count, current, list);
s=server_count-s;
selected_server=servers;
for(f=0; f<s; f++) selected_server=selected_server->next;
set_dialog_text(this_dialog,this_ob,selected_server->name);
for(f=0; f<server_count; f++) free(list[f]);
free(list);
return TRUE;
}
short delete_server(void)
{
server_list *l,*ll;
short f, current;
if (selected_server==&servers_default) return TRUE;
l=servers; ll=NULL; current=-1;
for(f=server_count-1; (f>-1)&&(current==-1); f--)
if (selected_server==l)
{
current=f;
}else{
ll=l;
l=l->next;
}
if (current==-1) return TRUE;
for(f=current; f<server_count; f++)
server_name_list[f]=server_name_list[f+1];
if (ll) // Unhitch the deleted element from the servers list
ll->next=l->next;
else
servers=l->next;
free(l->name); // dispose of the server entry
free(l->ip_name);
free(l->login);
free(l->password);
free(l->path);
free(l);
server_count--;
if (servers==NULL) // prevent a totally empty list
{
servers=&servers_default;
server_name_list[0]=servers->name;
server_count=1;
}
// Update the list of servers
Change_scroll_list(Hosts, Listhosts, server_name_list, server_count);
// Make the current editable texts our new ones
for(l=servers; l->next; l=l->next);
set_dialog_text(Hosts, Server_name, l->name);
set_dialog_text(Hosts, Ip_address, l->ip_name);
set_dialog_text(Hosts, Login_name, l->login);
set_dialog_text(Hosts, Login_password, l->password);
set_dialog_text(Hosts, Login_path, l->path);
Set_dialog_Kfocus(Hosts, Server_name);
set_dialog_text(Mainwindow, This_server, l->name);
selected_server=l;
dialog_update(Hosts);
dialog_update(Mainwindow);
for(f=1; f; graf_mkstate(¤t,¤t,&f,¤t));
return TRUE;
}